


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    def minDepth(self, root: TreeNode) -> int:
        if not root:
            return 0
        now_list = [root]
        count = 1
        flag = True
        while flag:
            next_list = []
            for item in now_list:
                if not item.left and not item.right:
                    flag = False
                    break
                if item.left:
                    next_list.append(item.left)
                if item.right:
                    next_list.append(item.right)
            if not flag:
                break
            else:
                count += 1
                now_list = next_list
        return count
